define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'express/order/index' + location.search,
                    add_url: 'express/order/add',
                    edit_url: '',
                    del_url: '',
                    multi_url: 'express/order/multi',
                    import_url: 'express/order/import',
                    table: 'express_order',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'order_no', title: __('Order_no'), operate: 'LIKE'},
                        {field: 'express_name', title: __('Express_name'), operate: 'LIKE'},
                        {field: 'express_img', title: __('Express_img'), operate:false,formatter: Table.api.formatter.image},
                        {field: 'express_no', title: __('Express_no'), operate: 'LIKE'},
                        {field: 'express_uid', title: __('Express_uid')},
                        {field: 'experssuser.username', title: __('User.username'), operate: 'LIKE'},
                        {field: 'experssuser.mobile', title: __('User.mobile'), operate: 'LIKE'},
                        {field: 'user_id', title: __('User_id')},
                        {field: 'user.nickname', title: __('User.username'), operate: 'LIKE'},
                        {field: 'start_door_time', title: __('Start_door_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'end_door_time', title: __('End_door_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        // {field: 'goods_type', title: __('Goods_type'), operate: 'LIKE'},
                        {field: 'goods_level', title: __('Goods_level'), operate: 'LIKE'},
                        {field: 'goods_weight', title: __('Goods_weight'), operate: 'LIKE'},
                        {field: 'goods_status', title: __('Goods_status'), searchList: {"0":__('Goods_status 0'),"1":__('Goods_status 1'),"2":__('Goods_status 2'),"3":__('Goods_status 3'),"4":__('Goods_status 4')}, formatter: Table.api.formatter.status},
                       /* {field: 'goods_cancel_obj', title: __('Goods_cancel_obj'), searchList: {"nil":__('Goods_cancel_obj nil'),"user":__('Goods_cancel_obj user'),"express":__('Goods_cancel_obj express')}, formatter: Table.api.formatter.normal},
                        {field: 'goosd_cancel_memo', title: __('Goosd_cancel_memo'), operate: 'LIKE'},*/
                        {field: 'pay_type', title: __('Pay_type'), searchList: {"0":__('Pay_type 0'),"1":__('Pay_type 1')}, formatter: Table.api.formatter.normal},
                        {field: 'pay_status', title: __('Pay_status'), searchList: {"0":__('Pay_status 0'),"1":__('Pay_status 1')}, formatter: Table.api.formatter.status},
                      //  {field: 'pay_order_no', title: __('Pay_order_no'), operate: 'LIKE'},
                        {field: 'pay_price', title: __('Pay_price'), operate:'BETWEEN'},
                        {field: 'pay_time', title: __('Pay_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'total_price', title: __('Total_price'), operate:'BETWEEN'},
                        {field: 'express_price', title: __('Express_price'), operate:'BETWEEN'},
                        {field: 'fee_price', title: __('Fee_price'), operate:'BETWEEN'},
                        /*{field: 'coupon_type', title: __('Coupon_type')},
                        {field: 'coupon_id', title: __('Coupon_id')},
                        {field: 'coupon_price', title: __('Coupon_price'), operate:'BETWEEN'},
                        */
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate, buttons: [
                                {name: 'detail', text:__('Detail'), title:__('Detail'), icon: 'fa fa-list', classname: 'btn btn-xs btn-primary btn-dialog', url: 'express/order/detail'}
                            ],}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
